﻿<UserControl
    x:Class="Markup.Programming.Samples.PasswordSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://markupprogramming.codeplex.com/markup/programming"
    Height="300" Width="300">
    <Grid>
        <StackPanel>
            <StackPanel.Resources>
                <SolidColorBrush Color="Red" x:Key="RedBrush"/>
                <SolidColorBrush Color="Green" x:Key="GreenBrush"/>
            </StackPanel.Resources>
            <TextBlock FontSize="20" Text="The password is: xyzzy"/>
            <TextBox FontSize="20" Name="Password"/>
            <Grid>
                <TextBlock FontSize="20" Foreground="White" FontWeight="Bold"/>

                <p:Attached.Operations>
                    <p:ChangedHandler Value="{Binding Text, ElementName=Password}">
                        <p:Set Var="$redBrush" Value="{StaticResource RedBrush}"/>
                        <p:Set Var="$greenBrush" Value="{StaticResource GreenBrush}"/>
                        <p:Script>
                            /* Check if the new value is right and set the status and color. */
                            var $isRight = @EventArgs.NewValue == "xyzzy";
                            @AssociatedObject.Children[0].Text = $isRight ? "On the money!" : "Guess again.";
                            @AssociatedObject.Background = $isRight ? $greenBrush : $redBrush;
                        </p:Script>
                    </p:ChangedHandler>
                </p:Attached.Operations>

            </Grid>
        </StackPanel>
    </Grid>
</UserControl>
